package antrace;

public class ForestGameLayer extends AbstractGameLayer {
	
	static int blockWidth = 48*3;
	
	public ForestGameLayer() {

		super(blockWidth, 4,  AntRace.midlet.loadImage("/images/tiles/foresttiles.png").image, 20, 20);
	
		byte[] cells = {
				0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
				0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
				0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
				
				0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 2, 3, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0,
				0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 2, 3, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0,
				0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 2, 3, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0,
				
				0, 0, 0, 0, 0, 3, 1, 4, 0, 0, 0, 0, 0, 0, 3, 1, 4, 0, 0, 0, 0, 3, 1, 1, 1, 1, 4, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 1, 4, 0, 0, 0, 0,
				0, 0, 0, 0, 0, 3, 1, 4, 0, 0, 0, 0, 0, 0, 3, 1, 4, 0, 0, 0, 0, 3, 1, 1, 1, 1, 4, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 1, 4, 0, 0, 0, 0,
				0, 0, 0, 0, 0, 3, 1, 4, 0, 0, 0, 0, 0, 0, 3, 1, 4, 0, 0, 0, 0, 3, 1, 1, 1, 1, 4, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 1, 4, 0, 0, 0, 0,
				
				5, 6, 7, 0, 3, 1, 1, 1, 4, 0, 5, 7, 0, 3, 1, 1, 1, 4, 0, 0, 3, 1, 1, 1, 1, 1, 1, 4, 0, 5, 7, 0, 3, 1, 4, 0, 5, 6, 7, 0, 3, 1, 1, 1, 4, 0, 5, 7,
				5, 6, 7, 0, 3, 1, 1, 1, 4, 0, 5, 7, 0, 3, 1, 1, 1, 4, 0, 0, 3, 1, 1, 1, 1, 1, 1, 4, 0, 5, 7, 0, 3, 1, 4, 0, 5, 6, 7, 0, 3, 1, 1, 1, 4, 0, 5, 7,
				5, 6, 7, 0, 3, 1, 1, 1, 4, 0, 5, 7, 0, 3, 1, 1, 1, 4, 0, 0, 3, 1, 1, 1, 1, 1, 1, 4, 0, 5, 7, 0, 3, 1, 4, 0, 5, 6, 7, 0, 3, 1, 1, 1, 4, 0, 5, 7,
		};
		
		this.createTiledLayerFromArray(cells, blockWidth);
		this.setPosition(0, 0);
	}

	public void collide(AntSprite sprite) {
		// do nothing
	}
	
	public void scroll(int dx) {
		
		//avrundar förlyttningen till halva
		int x = this.getX() - (int) Math.ceil((double) dx/2.0);
			
		// När lagret tar slut, börja om från början... (oändligt repterande bakgrund)
		if(this.getX() < -2*48*20) {
			x += 2*48*20;
		}
		else if(this.getX() > 0) {
			x -= 2*48*20;
		}
		
		setPosition(x, this.getY());
	}
	
	public void update() {
		// TODO Inget som uppdateras här än...
	}
}
